package com.nineclock.system.controller;

import com.nineclock.api.system.SysCompanyUserControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController implements SysCompanyUserControllerApi {
    @Autowired
    private SysCompanyUserService companyUserService;

    /**
     * 根据用户ID或企业ID 查询用户信息
     * @param userId
     * @param companyId
     * @return
     */
    @Override
    @GetMapping("/query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser( //required=false; 该参数可以不传
        	@RequestParam(value = "userId", required = false) Long userId,
            @RequestParam(value = "companyId", required = false) Long companyId){

        List<SysCompanyUserDTO> companyUserDTOS =
            companyUserService.queryCompanyUser(userId, companyId);

        return Result.success(companyUserDTOS);
    }

    /**
     * 根据ID查询企业员工信息
     * @param companyUserId
     * @return
     */
    @Override
    @GetMapping("/query/{companyUserId}")
    public Result<SysCompanyUserDTO> queryByCompanyUserId(@PathVariable("companyUserId") Long companyUserId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryByCompanyUserId(companyUserId);
        return Result.success(companyUserDTO);
    }

    /**
     * 查询当前企业所有的员工
     * @return
     */
    @GetMapping("/queryAllUser")
    public Result<List<SysCompanyUserDTO>> queryAllCompanyUser(){
        List<SysCompanyUserDTO> companyUserDTOS = companyUserService.queryAllCompanyUser();
        return Result.success(companyUserDTOS);
    }

    /**
     * 根据手机号获取企业员工信息
     * @param mobile
     * @return
     */
    @Override
    @GetMapping("/queryone")
    public Result<SysCompanyUserDTO> findCompanyUserByMobile(String mobile) {
        SysCompanyUserDTO companyUser = companyUserService.findCompanyUserByMobile(mobile);
        return Result.success(companyUser);
    }

    /**
     * 根据企业ID查询企业的主管理员信息
     * @param companyId
     * @return
     */
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(@RequestParam(value = "companyId", required = false) Long companyId){
        SysCompanyUserDTO companyUserDTO = companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }
}